home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Revolution - Das Atari CD Magazin 1997
/
Revolution - Das Atari CD Magazin 1.iso
/
software
/
anwendng
/
qed_397
/
sourcen
/
makro.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-12-29
|
12KB
|
578 lines
#include "global.h"
#include "clipbrd.h"
#include "desktop.h"
#include "icon.h"
#include "memory.h"
#include "menu.h"
#include "obj.h"
#include "rsc.h"
#include "scroll.h"
#include "text.h"
#include "windows.h"
#include "makro.h"
/* exportierte Variablen ************************************************/
BOOLEAN makro_play, makro_rec;
/*======================================================================*/
#define MAKRO_MAX 20 /* Makro Anzahl */
#define MAKRO_PLAY_LEN 100 /* Makrolen expanded */
#define MAKRO_DEF_LEN 100 /* einzelne Makrolänge */
#define UNUSED 0 /* Werte für mode */
#define TASTEN 1
#define BLOCK 2
/*======================================================================*/
typedef struct{
WORD scan;
WORD ascii;
UWORD nk; /* normalized key */
} T_KEY;
typedef struct {
BOOLEAN mode;
WORD len;
WORD key; /* F1 .. F20 */
UBYTE name[10];
union
{
T_KEY puffer[MAKRO_DEF_LEN];
RING text;
} daten;
} T_MAKRO;
/*======================================================================*/
LOCAL T_KEY makro_puffer[MAKRO_PLAY_LEN],
*makro_ptr, *makro_end;
LOCAL T_MAKRO makro_list[MAKRO_MAX],
*makro_rec_ptr,
*makro_play_ptr;
LOCAL WORD makro_play_counter;
/*======================================================================*/
LOCAL VOID t_key2mk(CONST T_KEY *t_key, MKINFO *mk)
{
mk->kreturn = t_key->nk;
mk->ascii_code = t_key->ascii;
mk->scan_code = t_key->scan;
mk->shift = (t_key->nk & NKF_SHIFT) != 0;
mk->ctrl = (t_key->nk & NKF_CTRL) != 0;
mk->alt = (t_key->nk & NKF_ALT) != 0;
}
LOCAL VOID mk2t_key(CONST MKINFO *mk, T_KEY *t_key)
{
t_key->scan = mk->scan_code;
t_key->ascii = mk->ascii_code;
t_key->nk = mk->kreturn;
}
VOID set_makro_str(UBYTE *ptr)
{
WORD l, i, v;
UBYTE *p, name[10];
T_MAKRO *m;
p = strchr(ptr,'@');
if (!p)
return;
*p = EOS;
*(UBYTE*)COPYB(name,ptr,8) = EOS;
ptr = p+1;
p = strchr(ptr,'@');
if (!p)
return;
*p = EOS;
v = atoi(ptr);
ptr = p+1;
for (i=MAKRO_MAX,m=makro_list; (--i)>=0; m++) /* Eintrag suchen */
{
if (m->key == v) /* Alten Eintrag erweitern */
break;
}
if (i<0)
for (i=MAKRO_MAX,m=makro_list; (--i)>=0; m++) /* Eintrag suchen */
{
if (m->mode==UNUSED) /* Leerer Eintrag */
{
strcpy(m->name,name);
m->key = v;
m->len = 0;
m->mode = TASTEN;
if (v==-1)
makro_rec_ptr = m;
else
set_fkey(v, name);
break;
}
}
if (i>=0)
{
l = m->len;
while((p = strchr(ptr,'@')) != NULL)
{
*p = EOS;
m->daten.puffer[l].nk = atoi(ptr);
ptr = p+1;
p = strchr(ptr,'@');
if (p)
*p = EOS;
v = atoi(ptr);
m->daten.puffer[l].scan = (UBYTE)(v>>8);
m->daten.puffer[l].ascii = (UBYTE)v;
l++;
if (!p)
break;
ptr = p+1;
}
m->len = l;
}
}
BOOLEAN get_makro_str(WORD *nr, UBYTE *ptr)
{
LOCAL WORD break_j;
UBYTE s[20];
WORD end, i, j = 0;
if (*nr==-1)
{
break_j = 0;
*nr = 0;
}
for (i=MAKRO_MAX; (--i) >= 0; )
if (makro_list[i].mode == TASTEN) /* nur Tasten-Makros */
{
if (*nr==j)
break;
j++;
}
if (i>=0) /* Makro existiert */
{
ptr = COPYB(ptr, makro_list[i].name, (short) strlen(makro_list[i].name)); /* Name */
*ptr++ = '@';
itoa(makro_list[i].key, s, 10);
ptr = COPYB(ptr, s, (short) strlen(s)); /* Key */
j = break_j;
if (j + 8 < makro_list[i].len)
end = j+8;
else
end = makro_list[i].len;
for ( ; j<end; j++)
{
*ptr++ = '@';
itoa(makro_list[i].daten.puffer[j].nk, s, 10);
ptr = COPYB(ptr, s, (short) strlen(s));
*ptr++ = '@';
itoa((makro_list[i].daten.puffer[j].scan << 8) + makro_list[i].daten.puffer[j].ascii, s, 10);
ptr = COPYB(ptr, s, (short) strlen(s));
}
*ptr = EOS;
if (j<makro_list[i].len)
{
break_j = j;
}
else
{
break_j = 0;
(*nr)++;
}
return TRUE;
}
return FALSE;
}
VOID del_makro(WORD key)
{
T_MAKRO *m;
WORD i;
m = makro_list;
for (i=MAKRO_MAX; (--i)>=0; m++)
if (m->mode != UNUSED && m->key == key)
{
if (makro_rec_ptr!=NULL && makro_rec_ptr==m)
{
m->key = -1;
}
else
{
if (m->mode==BLOCK)
kill_textring(&m->daten.text);
m->mode = UNUSED;
}
set_fkey(key,"");
draw_fkey(key, FALSE);
break;
}
}
VOID get_makro_name(WORD scan, UBYTE *name)
{
WORD i;
T_MAKRO *m;
*name = EOS;
m = makro_list;
for (i=MAKRO_MAX; (--i)>=0; m++)
if (m->mode!=UNUSED && m->key == scan)
{
strcpy(name, m->name);
break;
}
}
BOOLEAN pre_makro(MKINFO *mk)
{
if (makro_play) /* Macro abspielen */
{
retry:
if (makro_ptr < makro_end)
{
t_key2mk(makro_ptr, mk);
makro_ptr++;
return TRUE;
}
else /* Abspielen beenden */
{
if (makro_play_counter > 1)
{
makro_play = FALSE;
start_play(makro_play_ptr->key, makro_play_counter-1);
goto retry;
}
else
end_play();
}
}
return FALSE;
}
VOID post_makro(MKINFO *mk)
{
if (makro_rec && !makro_play) /* Zeichen erfassen */
/* wenn echtes Zeichen */
{
WORD pos = makro_rec_ptr->len;
if (pos < MAKRO_DEF_LEN)
{
mk2t_key(mk, &(makro_rec_ptr->daten.puffer[pos]));
makro_rec_ptr->len++;
}
else
mybeep();
}
}
VOID start_blk_rec(UBYTE *name, WORD key, RINGPTR r)
{
WORD new, i;
T_MAKRO *m;
new = -1;
m = makro_list;
for (i=0; i<MAKRO_MAX; i++,m++) /* Eintrag suchen */
{
if (m->mode==UNUSED) /* Leerer Eintrag */
new = i;
else if (m->key == key) /* Alten Eintrag überschreiben */
{
new = i;
break;
}
}
if (new >- 1)
{
m = makro_list+new;
if (m->mode == BLOCK)
free_textring(&m->daten.text);
else
init_textring(&m->daten.text);
m->len = 0; /* leeren */
m->mode = BLOCK;
m->key = key;
doppeln(r,&m->daten.text);
strcpy(m->name,name);
set_fkey(key,name);
draw_fkey(key,FALSE);
}
}
VOID start_rec(VOID)
{
WORD new, i;
T_MAKRO *m;
if (makro_rec_ptr!=NULL)
{
m = makro_rec_ptr;
if (m->key == -1)
m->key = UNUSED;
makro_rec_ptr = NULL;
}
new = -1;
m = makro_list;
for (i=0; i<MAKRO_MAX; i++,m++) /* Eintrag suchen */
{
if (m->mode==UNUSED) /* Leerer Eintrag */
new = i;
}
if (new>-1) /* Gefunden */
{
m = &makro_list[new];
makro_rec = TRUE; /* Zeichen erfassen */
makro_rec_ptr = m;
m->len = 0; /* leeren */
m->key = -1;
m->name[0] = EOS;
print_headline(" Makro-Rec ");
menu_text(menu, MSRECORD, STRING(MSTOPSTR));
}
}
VOID end_rec(BOOLEAN one_more)
{
WORD len = makro_rec_ptr->len;
makro_rec = FALSE;
if (len>1)
{
if (one_more)
makro_rec_ptr->len--; /* letztes ^M raus */
makro_rec_ptr->mode = TASTEN; /* Makro ist O.K. */
}
else
makro_rec_ptr = NULL;
print_headline(" ");
menu_text(menu, MSRECORD, STRING(MRECSTR));
}
VOID makro_on_key(UBYTE *name, WORD key)
{
T_MAKRO *m;
if (makro_rec_ptr!=NULL)
{
del_makro(key);
m = makro_rec_ptr;
makro_rec_ptr = NULL;
m->key = key;
strcpy(m->name, name);
set_fkey(key, name);
draw_fkey(key, FALSE);
}
}
BOOLEAN start_play(WORD key, WORD anz)
{
WORD i;
T_MAKRO *m;
BOOLEAN ret = FALSE;
if (key == -1) /* aktuelles Makro */
{
m = makro_rec_ptr;
if (m == NULL)
{
mybeep();
return FALSE;
}
}
else /* Funktionstaste */
{
m = makro_list;
for (i=0; i<MAKRO_MAX; i++,m++) /* Eintrag suchen */
if (m->mode!=UNUSED && m->key==key)
break;
if (i == MAKRO_MAX)
{
mybeep();
return FALSE;
}
}
if (m->mode == TASTEN) /* Eintrag gefunden */
{
if (!makro_play) /* Neues M. starten */
{
Arrow_mouse();
if (m->key>=0)
draw_fkey (m->key,TRUE);
COPYW(makro_puffer, m->daten.puffer, m->len * (short) sizeof(T_KEY));
makro_end = makro_puffer+m->len;
makro_ptr = makro_puffer;
makro_play = TRUE;
makro_play_ptr = m;
makro_play_counter = max(1,anz);
print_headline("Makro-Play ");
ret = TRUE;
}
else /* Makro ruft Makro auf */
{
WORD len_old = (short) (makro_end - makro_ptr);
WORD len_new = m->len;
if (len_old+len_new < MAKRO_PLAY_LEN)
{
/* Alten Rest nach hinten verschieben */
MOVE((UBYTE*)&makro_puffer[len_new],(UBYTE*)makro_ptr,len_old * (short) sizeof(T_KEY));
/* Neues Makro einfügen */
COPYW(makro_puffer,m->daten.puffer,m->len * (short) sizeof(T_KEY));
makro_end = makro_puffer+(len_old+len_new);
makro_ptr = makro_puffer;
ret = TRUE;
}
else
mybeep();
}
}
else if(m->mode==BLOCK && !makro_rec && !makro_play)
{
RING t;
draw_fkey(m->key, TRUE);
init_textring(&t);
doppeln(&m->daten.text,&t);
clip_takes_text(&t);
do_action(DO_PASTE);
draw_fkey(m->key, FALSE);
ret = TRUE;
}
else /* Kein Eintrag gefunden */
mybeep();
return ret;
}
VOID end_play(VOID)
{
T_MAKRO *m;
if (makro_play)
{
m = makro_play_ptr;
if (m->key>=0)
draw_fkey (m->key,FALSE);
makro_play = FALSE;
makro_play_ptr = NULL;
print_headline(" ");
}
}
VOID init_makro(VOID)
{
WORD i;
T_MAKRO *m;
makro_play = makro_rec = FALSE;
for (i=MAKRO_MAX,m=makro_list; (--i)>=0; m++)
m->mode = UNUSED;
}
/***************************************************************************/
/* Dialog ******************************************************************/
/***************************************************************************/
LOCAL VOID show_makro(WORD nr)
/* 0..19 */
{
UBYTE name[9];
if (nr < 10)
get_makro_name(0x3B00 + (nr * 0x100), name);
else
get_makro_name(0x5400 + ((nr - 10) * 0x100), name);
objc_setstring(funktionstasten, FNNAME, name);
draw_Objc(funktionstasten, FNNAME, 1);
disable_objc(funktionstasten, FNDELETE, (name[0] == EOS));
draw_Objc(funktionstasten, FNDELETE, 1);
}
VOID makro_dial(VOID)
{
WORD antw, y, edobj;
UBYTE name[9];
TEXTP t_ptr;
DIALINFO dial;
BOOLEAN quit = FALSE;
WORD makro_nr = 0;
do_icon(iclipbrd, DO_UPDATE);
t_ptr = get_text(iclipbrd);
disable_objc(funktionstasten, FNBLOCK, ist_leer(&t_ptr->text));
objc_setstring(funktionstasten, FNNAME, "");
objc_setstring(funktionstasten, FNKEY, " F1");
Arrow_mouse();
open_dial(funktionstasten, FALSE, NULL, &dial);
dial_draw(&dial);
show_makro(makro_nr);
edobj = FNNAME;
do
{
antw = dial_do(&dial, &edobj) & 0x7FFF;
switch (antw)
{
case FNSTR :
case FNCIRCLE :
case FNKEY :
if (antw == FNCIRCLE)
y = popup_select(NIL, funktionstasten, FNKEY, popups, FUNCPOP, FALSE, DO_CYCLE, NULL, (POP_CB)NULL);
else
y = popup_select(NIL, funktionstasten, FNKEY, popups, FUNCPOP, FALSE, DO_POPUP, NULL, (POP_CB)NULL);
y -= POPF1;
if (y >= 0)
{
makro_nr = y;
show_makro(makro_nr);
}
break;
case FNDELETE:
if (makro_nr < 10)
del_makro(0x3B00 + (makro_nr * 0x100));
else
del_makro(0x5400 + ((makro_nr - 10) * 0x100));
show_makro(makro_nr);
select_objc(funktionstasten, antw, FALSE);
draw_Objc(funktionstasten, antw, 1);
break;
case FNRECORD:
case FNBLOCK:
objc_getstring(funktionstasten, FNNAME, name);
select_objc(funktionstasten, antw, FALSE);
draw_Objc(funktionstasten, antw, 1);
if (*name == EOS)
note(1, MKNAME);
else
quit = TRUE;
break;
default:
quit = TRUE;
break;
}
}
while (!quit);
select_objc(funktionstasten, antw, FALSE);
dial_end(&dial);
Last_mouse();
if (antw == FNRECORD)
{
if (makro_nr < 10)
makro_on_key(name, 0x3B00 + (makro_nr * 0x100));
else
makro_on_key(name, 0x5400 + ((makro_nr - 10) * 0x100) );
}
if (antw == FNBLOCK)
{
if (makro_nr < 10)
start_blk_rec(name, 0x3B00 + (makro_nr * 0x100), &t_ptr->text);
else
start_blk_rec(name, 0x5400 + ((makro_nr - 10) * 0x100), &t_ptr->text);
}
}